package com.example.ffmpegsharedstudy

import android.view.Surface
import android.view.SurfaceHolder
import android.view.SurfaceView

class WPlayer : SurfaceHolder.Callback {

    private var surfaceHolder: SurfaceHolder? = null

    fun setSurfaceView(surfaceView: SurfaceView){
        this.surfaceHolder?.removeCallback(this)

        this.surfaceHolder = surfaceView.holder
        surfaceHolder?.addCallback(this)
    }

    override fun surfaceCreated(p0: SurfaceHolder) {

    }

    override fun surfaceChanged(p0: SurfaceHolder, p1: Int, p2: Int, p3: Int) {
        surfaceHolder = p0
    }

    override fun surfaceDestroyed(p0: SurfaceHolder) {
    }

    fun start(path: String) {
         native_start(path,surfaceHolder?.surface)
    }

    external fun native_start(path: String, surface: Surface?)

    companion object {
        init {
            System.loadLibrary("ffmpegsharedstudy")
        }
    }
}